//
//  BIZTabBarController.m
//  jiedabao
//
//  Created by 小龙 on 2017/3/15.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZTabBarController.h"
#import "BIZTabBar.h"
#import "BIZNavigationController.h"
#import "BIZHomePageViewController.h"
#import "BIZConsultViewController.h"
#import "BIZFinanceTaxCircleVC.h"
#import "BIZFindServiceViewController.h"
#import "BIZMyTableViewController.h"
#import "BIZDWPlayerViewController.h"
#import "BIZBusinessPremisesListVC.h"

@interface BIZTabBarController ()<UITabBarControllerDelegate>

@end

@implementation BIZTabBarController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    
    // 初始化子控制器
    BIZHomePageViewController *home = [BIZHomePageViewController viewControllerFromStoryboard];
    [self addChildViewController:home title:@"首页" image:@"(编组)副本2" selectedImage:@"形状6副本"];
    
//    BIZConsultViewController *consult = [BIZConsultViewController viewControllerFromStoryboard];
//    [self addChildViewController:consult title:@"咨询" image:@"consulting" selectedImage:@"组6副本7"];
    BIZDWPlayerViewController *player =  [[BIZDWPlayerViewController alloc] init];
    [self addChildViewController:player title:@"在线课堂" image:@"在线" selectedImage:@"在线课堂"];
    
    BIZFinanceTaxCircleVC *vc = [[BIZFinanceTaxCircleVC alloc]init];
    BIZNavigationController *nav = [[BIZNavigationController alloc ]initWithRootViewController:vc];
    // 添加子控制器
    [self addChildViewController:nav];
    
//    BIZFindServiceViewController *find = [BIZFindServiceViewController viewControllerFromStoryboard];
//    [self  addChildViewController:find title:@"找服务" image:@"找服务" selectedImage:@"矩形15"];
    
    BIZBusinessPremisesListVC *businessPremisesListVC = [[BIZBusinessPremisesListVC alloc]init];
    [self addChildViewController:businessPremisesListVC title:@"事务所" image:@"形状1副本4" selectedImage:@"形状1副本5"];
    
    BIZMyTableViewController *mine = [BIZMyTableViewController viewControllerFromStoryboard];
    
    [self addChildViewController:mine title:@"我的" image:@"我副本" selectedImage:@"形状7副本"];
    
    BIZTabBar *tabBar = [[BIZTabBar alloc]init];
    self.delegate = self;
    [self setValue:tabBar forKey:@"tabBar"];
}

//- (BOOL)shouldAutorotate {
//    return NO;
//}
//
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return self.selectedViewController.supportedInterfaceOrientations;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return self.selectedViewController.preferredInterfaceOrientationForPresentation;
}

- (BOOL)shouldAutorotate {
    
    return self.selectedViewController.shouldAutorotate;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
}

-(void)addChildViewController:(UIViewController *)childController title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    
    childController.title = title;
    
    childController.tabBarItem.image = [UIImage imageNamed:image];
    childController.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    NSDictionary *dicNor = @{
                             NSForegroundColorAttributeName:HEXCOLOR(0x666666),
                             NSFontAttributeName:SYSTEMFONT(10)
                             };
    
    [childController.tabBarItem setTitleTextAttributes:dicNor forState:UIControlStateNormal];
    
    NSDictionary *dicSelected = @{
                                  NSForegroundColorAttributeName:HEXCOLOR(0x1777cb),
                                  NSFontAttributeName:SYSTEMFONT(10)
                                  };
    

    
    [childController.tabBarItem setTitleTextAttributes:dicSelected forState:UIControlStateSelected];
    
    // 先把外面传进来的控制器包装成一个导航控制器
    BIZNavigationController *nav = [[BIZNavigationController alloc ]initWithRootViewController:childController];
    // 添加子控制器
    [self addChildViewController:nav];
}



- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
//    if ([viewController.tabBarItem.title isEqualToString:@"找服务"]){
//        [MBProgressHUD showBottomTipMessageInWindow:@"敬请期待"];
//        return NO;
//    }
    
    return YES;
}

@end
